package com.lhoverc.mapper;

import com.lhoverc.pojo.VO.AnnouncementVO;
import com.lhoverc.pojo.VO.RecentAnnounceVO;
import com.lhoverc.pojo.dto.AnnouncementDto;
import com.lhoverc.pojo.entity.AnnouncementEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: LiCheng
 * @CreateTime: 2025-04-20
 * @Description:
 * @Version: 1.0
 */
@Mapper
public interface AnnouncementMapper {

    /**
     * 按更新时间排序获取除未展示，已删除外的数据
     * @return
     */
    @Select("select * from announcement where is_show = 1 and is_delete = 0 order by update_time desc")
    List<RecentAnnounceVO> pageRecentAnnouncement();

    /**
     * 按照title的查找按更新时间排序获取除未展示，已删除外的数据
     * @return
     */
    @Select("select * from announcement where is_show = 1 and is_delete = 0 and announcement_title like '%${title}%' order by update_time desc")
    List<RecentAnnounceVO> page(String title);

    /**
     * 查询所有的公告
     * @return
     */
    @Select("select * from announcement where is_delete = 0")
    List<AnnouncementVO> getAllAnnouncement();

    /**
     * 添加公告
     * @param announcementEntity
     */
    @Insert("insert into announcement (creator_id, announcement_title, announcement_content, create_time, update_time) values " +
            "(#{creatorId}, #{announcementTitle}, #{announcementContent}, #{createTime}, #{updateTime})")
    void addAnnouncement(AnnouncementEntity announcementEntity);

    /**
     * 删除公告
     * @param id
     */
    @Update("update announcement set is_delete = 1 where id = #{id}")
    void deleteAnnouncement(int id);

    @Update("update announcement set announcement_title = #{announcementTitle}, announcement_content = #{announcementContent}, is_show = #{isShow}, update_time = #{updateTime} where id = #{id}")
    void updateAnnouncement(AnnouncementEntity announcementEntity);
}
